<template>
  <div class="leaving-page">
    <div class="central">
      <div class="title">
        <h1>留言板</h1>
        <p>在这里留下你想说的话</p>
      </div>
      
      <div class="row central central-800">
        <!-- 留言表单 -->
        <div class="card col-lg-12 col-md-12 col-sm-12 col-sm-x-12">
          <div class="leaving-form animated fadeInUp">
            <h2>发表留言</h2>
            <form @submit.prevent="submitMessage">
              <div class="form-group">
                <label for="name">姓名:</label>
                <input 
                  type="text" 
                  id="name" 
                  v-model="messageForm.name" 
                  required
                  class="form-control"
                >
              </div>
              
              <div class="form-group">
                <label for="qq">QQ号码:</label>
                <input 
                  type="text" 
                  id="qq" 
                  v-model="messageForm.qq" 
                  required
                  class="form-control"
                >
              </div>
              
              <div class="form-group">
                <label for="content">留言内容:</label>
                <textarea 
                  id="content" 
                  v-model="messageForm.content" 
                  required
                  class="form-control"
                  rows="5"
                ></textarea>
              </div>
              
              <button type="submit" class="btn-submit">提交留言</button>
            </form>
          </div>
        </div>
        
        <!-- 留言列表 -->
        <div class="card col-lg-12 col-md-12 col-sm-12 col-sm-x-12">
          <div class="leaving-list animated fadeInUp delay-03s">
            <h2>留言列表</h2>
            <div 
              v-for="message in messages" 
              :key="message.id" 
              class="message-item"
            >
              <div class="message-header">
                <span class="message-name">{{ message.name }}</span>
                <span class="message-qq">QQ: {{ message.qq }}</span>
                <span class="message-time">{{ formatTime(message.time) }}</span>
              </div>
              <div class="message-content">
                {{ message.text }}
              </div>
            </div>
            
            <div v-if="messages.length === 0" class="no-messages">
              暂无留言，快来发表第一个留言吧！
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'LeavingView',
  data() {
    return {
      messageForm: {
        name: '',
        qq: '',
        content: ''
      },
      messages: [
        {
          id: 1,
          name: 'Ki.',
          qq: '3439780232',
          text: 'LikeGirl#5.1.0默认留言',
          time: '1718090394'
        }
      ]
    }
  },
  methods: {
    submitMessage() {
      // 这里应该调用API提交留言
      const newMessage = {
        id: this.messages.length + 1,
        name: this.messageForm.name,
        qq: this.messageForm.qq,
        text: this.messageForm.content,
        time: Math.floor(Date.now() / 1000).toString()
      };
      
      this.messages.unshift(newMessage);
      
      // 重置表单
      this.messageForm = {
        name: '',
        qq: '',
        content: ''
      };
      
      alert('留言提交成功！');
    },
    
    formatTime(timestamp) {
      const date = new Date(timestamp * 1000);
      return date.toLocaleString('zh-CN');
    }
  }
}
</script>

<style scoped>
.leaving-page {
  padding: 2rem 0;
}

.title {
  text-align: center;
  margin-bottom: 2rem;
}

.title h1 {
  font-size: 2rem;
  color: #333;
  margin-bottom: 0.5rem;
}

.title p {
  color: #666;
}

.leaving-form, .leaving-list {
  padding: 1.5rem;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,.1);
  margin-bottom: 2rem;
}

.leaving-form h2, .leaving-list h2 {
  margin-top: 0;
  margin-bottom: 1.5rem;
  color: #333;
}

.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: bold;
  color: #333;
}

.form-control {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 1rem;
  box-sizing: border-box;
}

.form-control:focus {
  outline: none;
  border-color: #007bff;
  box-shadow: 0 0 0 2px rgba(0,123,255,.25);
}

.btn-submit {
  background-color: #007bff;
  color: white;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
}

.btn-submit:hover {
  background-color: #0056b3;
}

.message-item {
  border-bottom: 1px solid #eee;
  padding: 1.5rem 0;
}

.message-item:last-child {
  border-bottom: none;
}

.message-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.message-name {
  font-weight: bold;
  color: #333;
}

.message-qq {
  color: #007bff;
  font-size: 0.9rem;
}

.message-time {
  color: #999;
  font-size: 0.9rem;
}

.message-content {
  color: #666;
  line-height: 1.6;
}

.no-messages {
  text-align: center;
  color: #999;
  padding: 2rem 0;
}

@media (max-width: 768px) {
  .message-header {
    flex-direction: column;
    gap: 0.5rem;
  }
}
</style>
